<template>
  <div class="home">
    <!-- 导航栏 -->
    <van-nav-bar>
      <!-- 自定义左侧 -->
      <template #left>
        <div class="logo"></div>
      </template>
      <!-- 自定义右侧插件 -->
      <template #right>
        <van-button
          @click="$router.push('/search')"
          class="search-btn"
          icon="search"
          round
          type="primary"
          >搜索</van-button
        >
      </template>
    </van-nav-bar>
    <!-- 频道栏 -->
    <van-tabs class="channel-tabs">
      <van-tab
        v-for="(item, index) in ownChannels"
        :key="item.id"
        :title="item.name"
      >
        <!-- 内容 {{ index }} -->
        <articleList :channel_id="item.id" />
      </van-tab>

      <!-- 用来放图标的div -->
      <div class="icon-box"@click="show=true">
        <van-icon name="wap-nav" />
      </div>
    </van-tabs>

    <!-- 频道管理页面 sheet -->
    <template>
      <van-action-sheet v-model="show" title="最爱冠希">
      <channel-edit :ownChannels="ownChannels" :allChannels="allChannels" />
      </van-action-sheet>
    </template>
  </div>
</template>
  

    <!-- 结束 -->
  </div>
</template>

<script>
/// 导入接口
import { userChannelsAPI ,channelsAllAPI} from "@/api";
// import { userChannelsAPI } from "@/api";

// 导入新闻列表组件
import articleList from "./articleList.vue";
//导入频道管理组件
import channelEdit from "./channelEdit.vue";
export default {
  // 注册成子组件
  components: {
    articleList,
    channelEdit,
  },
  data() {
    return {
   
      show:false,
      // 保存用户自己的频道
      ownChannels: [],
      //所有频道
      allChannels:[],

    };
  },

  async created() {
    // 1.发请求，获取用户自己的频道
    let res = await userChannelsAPI();
    this.ownChannels = res.data.data.channels;
    // console.log(res);

     // 2. 获取所有频道
    let res2 = await channelsAllAPI()
    this.allChannels = res2.data.data.channels
  },
};
</script>

<style scoped lang="less">
//导航栏背景色
.van-nav-bar {
  background-color: #3196fa !important;
}
.logo {
  width: 120px;
  height: 100%;
  // 因为@在less有特殊含义，所以如果你想让@代表src目录，前面加一个~代表转义
  background: url(~@/assets/logo.png) no-repeat center / contain;
}

.search-btn {
  width: 100px;
  height: 30px;
  background-color: rgba(255, 255, 255, 0.2);
  border: none;

  .van-icon-search {
    color: #fff;
  }
}

// 频道栏
.channel-tabs {
  position: relative;

  // 包tab栏的盒子
  ::v-deep {
    .van-tabs__wrap {
      width: 345px;
    }
  }

  // 图标
  .icon-box {
    position: absolute;
    top: 5px;
    right: 0;
    background-color: #fff;

    .van-icon-wap-nav {
      font-size: 30px;
    }
  }
}
</style>